package cn.lingyangwl.agile.system.model.rqrs.dept;

import cn.lingyangwl.framework.tool.core.tree.TreeNode;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author shenguangyang
 */
@Getter
@Setter
public class DeptTreeDept implements TreeNode<Long, DeptTreeDept>, Serializable {
    private static final long serialVersionUID = 1L;
    /** 树的ID */
    protected Long id;

    /** 上一级树的id */
    protected Long parentId;

    /** 树的名称 */
    protected String name;

    /** 前端数据树中的key*/
    protected String key;

    /** 若父节点无其他子节点，则该父节点是叶子节点 */
    protected Boolean isLeaf;

    /** 图标 */
    protected String icon;

    /** 前端数据树中的value*/
    protected String value;

    /** 前端数据树中的title */
    protected String title;

    protected String slotTitle;

    /** 子节点 */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    protected List<DeptTreeDept> children;

    /** 排序 */
    protected Integer sortNo;

    /** 是否配置菜单的数据权限 1是, 0否 默认0 */
    private Integer ruleFlag;

    public DeptTreeDept(DeptResp dept) {
        this.key = String.valueOf(dept.getId());
        this.value = String.valueOf(dept.getId());
        this.title = dept.getDeptName();
        this.children = dept.getChildren().stream().map(DeptTreeDept::new).collect(Collectors.toList());
    }

    @Override
    public Long treeId() {
        return this.id;
    }

    @Override
    public void treeId(Long id) {
        this.id = id;
    }

    @Override
    public Long treeParentId() {
        return this.getParentId();
    }

    @Override
    public void treeParentId(Long parentId) {
        this.parentId = parentId;
    }

    @Override
    public List<DeptTreeDept> children() {
        return this.children;
    }

    @Override
    public String name() {
        return this.name;
    }

    @Override
    public void children(List<DeptTreeDept> children) {
        this.children = children;
    }

    @Override
    public Integer sortNo() {
        return this.getSortNo();
    }
}
